package com.lyz.dz.des.utile;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;


/**
 * 当地日期时间conqverter
 *
 * @author Administrator
 * @date 2021/06/20
 */
public class LocalDateTimeConqverter implements Converter<Date> {

    @Override
    public Class<Date> supportJavaTypeKey() {
        return Date.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
                                           GlobalConfiguration globalConfiguration) {
        return null;
    }

    @Override
    public CellData<String> convertToExcelData(Date value, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) {
//        System.out.println(value);
        Calendar calendar = Calendar.getInstance();

              calendar.clear();

            calendar.setTime(value);

          TimeZone timeZone = TimeZone.getTimeZone("GMT+08:00");
            calendar.setTimeZone(timeZone);
//        System.out.println();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        String format = simpleDateFormat.format(calendar.getTimeInMillis());
        System.out.println(format);
        CellData<String> objectCellData = new CellData<>( format);
        return objectCellData;
    }

}
